#include "ProductSpace.hpp"
#include "ElementarySpace.hpp"

#include <iostream>

void testConstructionFromElementary(int *numPassed, int *numTests);
void testPowerOfElementarySpaces(int *numPassed, int *numTests);
void printStatus(int status, int *numPassed);

int main(int argn, char **argv) {

	int numPassed = 0;
	int numTests = 0;

	std::cout << "\n ====== unit tests for ProductSpace\n";

	testConstructionFromElementary(&numPassed, &numTests);
	testPowerOfElementarySpaces(&numPassed, &numTests);

	std::cout << " ====== passed " << numPassed << "/" << numTests <<
		"\n" << std::endl;

	return 0;
}

void testConstructionFromElementary(int *numPassed, int *numTests) {
	++*numTests;
	int status = 1;
	std::cout <<  "  testConstructionFromElementary .................. ";
	ElementarySpace h1("h1", 2);
	ProductSpace ps1(h1);
	if (ps1.dim() != 2) {
		status *= 0;
	}
	if (ps1.dim() != h1.dim()) {
		status *= 0;
	}
	if (ps1.subSpaces().size() != 1) {
		status *= 0;
	}
	printStatus(status, numPassed);
}

void testPowerOfElementarySpaces(int *numPassed, int *numTests) {
	++*numTests;
	int status = 1;
	std::cout <<  "  testPowerOfElementarySpaces...................... ";

	int numSpaces = 10;
	int dim = 2;
	int d = 1;
	ProductSpace ps;
	for (int i = 0; i < numSpaces; ++i) {
		ps *= ProductSpace(ElementarySpace(i, dim));
		d *= dim;
	}
	if (d != ps.dim()) {
		status *= 0;
	}
	if (numSpaces != ps.subSpaces().size()) {
		status *= 0;
	}
	printStatus(status, numPassed);
}

void printStatus(int status, int *numPassed) {
	if (status) {
		++*numPassed;
		std::cout << "passed." << std::endl;
	} else {
		std::cout << "failed." << std::endl;
	}
}
